package net.sipvip.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.DOM;
import com.google.gwt.user.client.Event;
import com.google.gwt.user.client.ui.DecoratedPopupPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Image;

public class JWplayer extends Image {
	
	DecoratedPopupPanel popup = new DecoratedPopupPanel(true);
    final String videostr;
    final String imagestr;
	public JWplayer(String videostrvar,String imagestrvar) {
		super();
		videostr = videostrvar;
		imagestr = imagestrvar;
		sinkEvents(Event.ONCLICK);
   	
	}
	
	
	public void onBrowserEvent(Event event) {
		switch (DOM.eventGetType(event)) {
		case Event.ONCLICK:
			GWT.log(this.getUrl(), null);
            String videoimagestr = jwplayerstr(videostr,imagestr);
			
			HTML player = new HTML(videoimagestr);
			popup.setWidget(player);
			int left = this.getAbsoluteLeft() - 10;
			int top = this.getAbsoluteTop() +this.getHeight() + 20;
			popup.setPopupPosition(left, top);
			popup.show();			

			break;

//		case Event.ONMOUSEOUT:
//			popup.removeFromParent();
//			break;
					
		default:
			break;
		}
	}

	String jwplayerstr(String videostr, String imgstr) {

		String playerstr = "<object id=\"player\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" name=\"player\" width=\"656\" height=\"400\">"
				+ "<param name=\"movie\" value=\"player.swf\" />"
				+ "<param name=\"allowfullscreen\" value=\"true\" />"
				+ "<param name=\"allowscriptaccess\" value=\"always\" />"
				+ "<param name=\"flashvars\" value=\"file="
				+ videostr
				+ "&image="
				+ imgstr
				+ "\" />"
				+ "<object type=\"application/x-shockwave-flash\" data=\"player.swf\" width=\"425\" height=\"344\">"
				+ "<param name=\"movie\" value=\"player.swf\" />"
				+ "<param name=\"allowfullscreen\" value=\"true\" />"
				+ "<param name=\"allowscriptaccess\" value=\"always\" />"
				+ "<param name=\"flashvars\" value=\"file="
				+ videostr
				+ "&image="
				+ imgstr
				+ "\" />"
				+ "<p><a href=\"http://get.adobe.com/flashplayer\">Get Flash</a> to see this player.</p>"
				+ "</object>" + "</object>";

		return playerstr;

	}
	
}
